home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Menu Fixer 1.0 Source / Menu fixer ƒ / MSG Shell ƒ / msg main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-15  |  4.1 KB  |  187 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg main.c
  4.  
  5. Purpose:    This module handles the event loop and event dispatching.
  6.  
  7.  
  8. Menu Fixer -=- synchronize menu IDs and menu resource IDs
  9. Copyright (C) 1993 Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "msg main.h"
  29. #include "msg integrity.h"
  30. #include "msg graphics.h"
  31. #include "msg menus.h"
  32. #include "msg environment.h"
  33. #include "fix.h"
  34. #include "fix files.h"
  35. #include "AppleEvents.h"
  36. #include "EPPC.h"
  37.  
  38. void main(void)
  39. {
  40.     gDone = FALSE;    
  41.     MaxApplZone();    
  42.     InitGraf(&thePort);
  43.     InitFonts();
  44.     FlushEvents(everyEvent, 0);
  45.     InitWindows();
  46.     InitMenus();
  47.     TEInit();
  48.     InitDialogs(0L);
  49.     InitCursor();
  50.     GetDateTime(&randSeed);
  51.     
  52.     CheckEnvironment();    
  53.     DoIntegrityCheck();    
  54.     InitEnvironment();    
  55.     InitProgram();
  56.     EventLoop();    
  57.     ShutDownEnvironment();
  58.     ExitToShell();
  59. }
  60.  
  61. void EventLoop(void)
  62. {
  63.     EventRecord        theEvent;
  64.     
  65.     while (!gDone)
  66.     {
  67.         SetCursor(&arrow);
  68.         HiliteMenu(0);
  69.         
  70.         if (WaitNextEvent(everyEvent, &theEvent, 30, 0L))
  71.             DispatchEvents(theEvent);
  72.     }
  73. }
  74.  
  75. void DispatchEvents(EventRecord gTheEvent)
  76. {
  77.     int                i;
  78.     OSErr            isHuman;
  79.     Point            thisPoint;
  80.     
  81.     switch (gTheEvent.what)
  82.     {
  83.         case mouseDown:
  84.             HandleMouseDown(gTheEvent);
  85.             break;
  86.         case keyDown:
  87.         case autoKey:
  88.             if(gTheEvent.modifiers & cmdKey)
  89.             {
  90.                 AdjustMenus();
  91.                 HandleMenu(MenuKey((char)(gTheEvent.message & charCodeMask)));
  92.             }
  93.             break;
  94.         case diskEvt:
  95.             if (HiWord(gTheEvent.message)!=noErr)
  96.             {
  97.                 DILoad();
  98.                 SetPt(&thisPoint, 120, 120);
  99.                 isHuman=DIBadMount(thisPoint, gTheEvent.message);
  100.                 DIUnload();
  101.             }
  102.             break;
  103.         case updateEvt:
  104.             BeginUpdate((WindowPtr)gTheEvent.message);
  105.             
  106.             for (i=0; i<NUM_HELP; i++)
  107.                 if ((WindowPtr)gTheEvent.message == gHelp[i])
  108.                     UpdateHelp(i);
  109.             
  110.             EndUpdate((WindowPtr)gTheEvent.message);
  111.             break;
  112.         case kHighLevelEvent:
  113.             if (gHasAppleEvents)
  114.                 AEProcessAppleEvent(&gTheEvent);
  115.             break;
  116.     }
  117. }
  118.  
  119. void HandleMouseDown(EventRecord gTheEvent)
  120. {
  121.     WindowPtr    theWindow;
  122.     int            windowCode;
  123.     long        windSize;
  124.     GrafPtr        oldPort;
  125.     int            i;
  126.     
  127.     windowCode=FindWindow(gTheEvent.where, &theWindow);
  128.     switch (windowCode)
  129.     {
  130.         case inMenuBar:
  131.             AdjustMenus();
  132.             HandleMenu(MenuSelect(gTheEvent.where));
  133.             break;
  134.         case inContent:
  135.             if(FrontWindow() != theWindow)
  136.                 SelectWindow(theWindow);
  137.             break;
  138.         case inSysWindow:
  139.             SystemClick(&gTheEvent, theWindow);
  140.             break;
  141.         case inDrag:
  142.             DragWindow(theWindow, gTheEvent.where, &gDragRect);
  143.             break;
  144.         case inGoAway:
  145.             if (TrackGoAway(theWindow, gTheEvent.where))
  146.             {
  147.                 for (i=0; i<NUM_HELP; i++)
  148.                     if (theWindow == gHelp[i])
  149.                         gHelp[i]=0L;
  150.                 
  151.                 DisposeWindow(theWindow);
  152.                 AdjustMenus();
  153.             }
  154.             break;
  155.         case inGrow:
  156.             gSizeRect = screenBits.bounds;
  157.             OffsetRect(&gSizeRect, gSizeRect.left, gSizeRect.top);
  158.             
  159.             windSize = GrowWindow(theWindow, gTheEvent.where, &gSizeRect);
  160.             if(windSize != 0)
  161.             {
  162.                 GetPort(&oldPort);
  163.                 SetPort(theWindow);
  164.                 EraseRect(&theWindow->portRect);
  165.                 SizeWindow(theWindow, LoWord(windSize), HiWord(windSize), TRUE);
  166.                 InvalRect(&theWindow->portRect);
  167.                 SetPort(oldPort);
  168.             }
  169.             break;
  170.         case inZoomIn:
  171.         case inZoomOut:
  172.             if(TrackBox(theWindow, gTheEvent.where, windowCode))
  173.             {
  174.                 GetPort(&oldPort);
  175.                 SetPort(theWindow);
  176.                 ZoomWindow(theWindow, windowCode, FALSE);
  177.                 InvalRect(&theWindow->portRect);
  178.                 SetPort(oldPort);
  179.             }
  180.             break;
  181.     }
  182. }
  183.  
  184. void ShutDownEnvironment(void)
  185. {
  186. }
  187.